#include "FreeMainWindow.h"
#include "3DScenePanel.h"
#include "ui_FreeMainWindow.h"

CFreeMainWindow::CFreeMainWindow(QWidget *parent, Qt::WindowFlags flags)
	:QMainWindow(parent, flags)
	,m_p3DScenePanel(new C3DScenePanel())
{
	ui = new Ui::FreeMainWindow();
	ui->setupUi(this);
}

CFreeMainWindow::~CFreeMainWindow()
{
	if(m_p3DScenePanel)
	{		
		delete m_p3DScenePanel;
		m_p3DScenePanel = NULL;
	}

	if (ui)
	{
		delete ui;
		ui = NULL;
	}
}

bool CFreeMainWindow::Initialize(IRenderContext *pRenderContext)
{				
	if(m_p3DScenePanel && m_p3DScenePanel->Initialize(pRenderContext))
	{
		return InitializeUI();
	}
	
	return false;
}

bool CFreeMainWindow::InitializeUI()
{ 
	//设置系统标题
	setWindowTitle(QString("FreeEarthQt"));
	setWindowIcon(QIcon(":/images/free_earth.png"));

	setDockNestingEnabled(true);
	//statusBar()->setObjectName(tr("StatusBar"));
	setContextMenuPolicy(Qt::NoContextMenu);

	showMaximized();

	if (m_p3DScenePanel)
	{
		QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Expanding);
		sizePolicy1.setHorizontalStretch(0);
		sizePolicy1.setVerticalStretch(0);
		sizePolicy1.setHeightForWidth(m_p3DScenePanel->sizePolicy().hasHeightForWidth());
		m_p3DScenePanel->setSizePolicy(sizePolicy1);

		ui->verticalLayout->addWidget(m_p3DScenePanel);
	}

	
	return true;
}

bool CFreeMainWindow::UnInitialize()
{
	if(m_p3DScenePanel)
	{
		m_p3DScenePanel->UnInitialize();
		return true;
	}
	return false;
}

bool CFreeMainWindow::eventFilter( QObject *obj, QEvent *event )
{
	return QMainWindow::eventFilter(obj, event);
}

bool CFreeMainWindow::event(QEvent *e)
{
	return QMainWindow::event(e);
}

